# Contributor: Holger Jaekel <holger.jaekel@gmx.de>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=proj
pkgver=9.3.1
pkgrel=0
pkgdesc="PROJ coordinate transformation software library"
url="https://proj.org/"
arch="all"
license="MIT"
makedepends="
	cmake
	curl-dev
	nlohmann-json
	samurai
	sqlite
	sqlite-dev
	tiff-dev
	"
checkdepends="
	bash
	gtest-dev
	"
subpackages="
	$pkgname-doc
	$pkgname-util:util
	$pkgname-dev
	"
source="
	https://download.osgeo.org/proj/proj-$pkgver.tar.gz
	builtins-tolerance.patch
	"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		local crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DUSE_EXTERNAL_GTEST=ON \
		-DRUN_NETWORK_DEPENDENT_TESTS=OFF \
		-DBUILD_TESTING="$(want_check && echo ON || echo OFF)" \
		$crossopts
	cmake --build build
}

check() {
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest --test-dir build --force-new-ctest-process -E '(test_network)'
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

util() {
	pkgdesc="Cartographic projection library (utilities)"

	amove usr/bin
}

sha512sums="
e97a76516c6bd82ec56563e757f6c3a04def57060f78b631ea50130c2b600df44e9df248366a1a4891efc4ea37707d0a8461c40a1aa8cae4a074a25e6517679b  proj-9.3.1.tar.gz
dfc84e13c771a2981177760412a995523dee99cfb02359194ab45e5a7ec614f542a1307fbc06d540811987f6c68234e57e78aafd7136203d3a3b3eae5f01ad6c  builtins-tolerance.patch
"
